#ifndef NETWORK_H
#define NETWORK_H

#include "dllspec.h"

#include <SFML/System.hpp>
#include <SFML/Network.hpp>
#include <queue>
#include <exception>

#include "packetwithsource.h"

class DLL_EXPORT Network : private sf::Thread
{
	public:
		Network();
		virtual ~Network();
		std::queue<PacketWithSource*>* GetReadyPackages();

		bool StartUDPListening(unsigned short port);

		void Send(sf::Packet& data, sf::IPAddress& server, unsigned short serverPort);

	private:
		bool threadRunning;
		sf::SocketUDP socket;
		unsigned short port;
		sf::Mutex queueMutex;
		std::queue<PacketWithSource*>* readyPackages;

		void PutPackageOnReadyQueue(sf::SocketUDP& thisSocket);

		virtual void Run();
};

#endif // NETWORK_H
